package com.youyi.yyviewsdklibrary.View.searchview.utils;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.graphics.Point;
import android.os.Build;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.animation.Interpolator;
import java.util.ArrayList;

public class SimpleAnimationUtils {
    public static final int ANIMATION_DURATION_DEFAULT = 250;

    public interface AnimationListener {
        boolean onAnimationCancel(View view);

        boolean onAnimationEnd(View view);

        boolean onAnimationStart(View view);
    }

    private SimpleAnimationUtils() {
    }

    public static Animator revealOrFadeIn(View view) {
        return revealOrFadeIn(view, 250);
    }

    public static Animator revealOrFadeIn(View view, int i) {
        return revealOrFadeIn(view, i, null, null);
    }

    public static Animator revealOrFadeIn(View view, int i, AnimationListener animationListener) {
        return revealOrFadeIn(view, i, animationListener, null);
    }

    public static Animator revealOrFadeIn(View view, int i, Point point) {
        return revealOrFadeIn(view, i, null, point);
    }

    public static Animator revealOrFadeIn(View view, AnimationListener animationListener) {
        return revealOrFadeIn(view, 250, animationListener, null);
    }

    public static Animator revealOrFadeIn(View view, Point point) {
        return revealOrFadeIn(view, 250, null, point);
    }

    public static Animator revealOrFadeIn(View view, AnimationListener animationListener, Point point) {
        return revealOrFadeIn(view, 250, animationListener, point);
    }

    public static Animator revealOrFadeIn(View view, int i, AnimationListener animationListener, Point point) {
        if (Build.VERSION.SDK_INT >= 21) {
            return reveal(view, i, animationListener, point);
        }
        return fadeIn(view, i, animationListener);
    }

    public static Animator hideOrFadeOut(View view, int i) {
        return hideOrFadeOut(view, i, null, null);
    }

    public static Animator hideOrFadeOut(View view, int i, AnimationListener animationListener) {
        return hideOrFadeOut(view, i, animationListener, null);
    }

    public static Animator hideOrFadeOut(View view, int i, Point point) {
        return hideOrFadeOut(view, i, null, point);
    }

    public static Animator hideOrFadeOut(View view) {
        return hideOrFadeOut(view, 250);
    }

    public static Animator hideOrFadeOut(View view, AnimationListener animationListener) {
        return hideOrFadeOut(view, 250, animationListener, null);
    }

    public static Animator hideOrFadeOut(View view, Point point) {
        return hideOrFadeOut(view, 250, null, point);
    }

    public static Animator hideOrFadeOut(View view, AnimationListener animationListener, Point point) {
        return hideOrFadeOut(view, 250, animationListener, point);
    }

    public static Animator hideOrFadeOut(View view, int i, AnimationListener animationListener, Point point) {
        if (Build.VERSION.SDK_INT >= 21) {
            return hide(view, i, animationListener, point);
        }
        return fadeOut(view, i, animationListener);
    }

    public static Animator reveal(View view, int i) {
        return reveal(view, i, null, null);
    }

    public static Animator reveal(View view, int i, Point point) {
        return reveal(view, i, null, point);
    }

    public static Animator reveal(View view, int i, AnimationListener animationListener) {
        return reveal(view, i, animationListener, null);
    }

    public static Animator reveal(View view) {
        return reveal(view, 250);
    }

    public static Animator reveal(View view, AnimationListener animationListener) {
        return reveal(view, 250, animationListener, null);
    }

    public static Animator reveal(View view, Point point) {
        return reveal(view, 250, null, point);
    }

    public static Animator reveal(View view, AnimationListener animationListener, Point point) {
        return reveal(view, 250, animationListener, point);
    }

    public static Animator reveal(View view, int i, AnimationListener animationListener, Point point) {
        if (point == null) {
            point = getDefaultCenter(view);
        }
        Animator createCircularReveal = ViewAnimationUtils.createCircularReveal(view, point.x, point.y, 0.0f, (float) getRevealRadius(point, view));
        createCircularReveal.addListener(new DefaultActionAnimationListener(view, animationListener) {
            /* class com.youyi.yyviewsdklibrary.View.searchview.utils.SimpleAnimationUtils.AnonymousClass1 */

            /* access modifiers changed from: package-private */
            @Override // com.youyi.yyviewsdklibrary.View.searchview.utils.SimpleAnimationUtils.DefaultActionAnimationListener
            public void defaultOnAnimationStart(View view) {
                view.setVisibility(View.VISIBLE);
            }
        });
        createCircularReveal.setDuration((long) i);
        createCircularReveal.setInterpolator(getDefaultInterpolator());
        return createCircularReveal;
    }

    public static Animator hide(View view, int i) {
        return hide(view, i, null, null);
    }

    public static Animator hide(View view, int i, Point point) {
        return hide(view, i, null, point);
    }

    public static Animator hide(View view, int i, AnimationListener animationListener) {
        return hide(view, i, animationListener, null);
    }

    public static Animator hide(View view) {
        return hide(view, 250);
    }

    public static Animator hide(View view, AnimationListener animationListener) {
        return hide(view, 250, animationListener, null);
    }

    public static Animator hide(View view, Point point) {
        return hide(view, 250, null, point);
    }

    public static Animator hide(View view, AnimationListener animationListener, Point point) {
        return hide(view, 250, animationListener, point);
    }

    public static Animator hide(View view, int i, AnimationListener animationListener, Point point) {
        if (point == null) {
            point = getDefaultCenter(view);
        }
        Animator createCircularReveal = ViewAnimationUtils.createCircularReveal(view, point.x, point.y, (float) getRevealRadius(point, view), 0.0f);
        createCircularReveal.addListener(new DefaultActionAnimationListener(view, animationListener) {
            /* class com.youyi.yyviewsdklibrary.View.searchview.utils.SimpleAnimationUtils.AnonymousClass2 */

            /* access modifiers changed from: package-private */
            @Override // com.youyi.yyviewsdklibrary.View.searchview.utils.SimpleAnimationUtils.DefaultActionAnimationListener
            public void defaultOnAnimationEnd(View view) {
                view.setVisibility(View.GONE);
            }
        });
        createCircularReveal.setDuration((long) i);
        createCircularReveal.setInterpolator(getDefaultInterpolator());
        return createCircularReveal;
    }

    protected static Point getDefaultCenter(View view) {
        return new Point(view.getWidth() / 2, view.getHeight() / 2);
    }

    protected static int getRevealRadius(Point point, View view) {
        ArrayList<Point> arrayList = new ArrayList();
        arrayList.add(new Point(view.getLeft(), view.getTop()));
        arrayList.add(new Point(view.getRight(), view.getTop()));
        arrayList.add(new Point(view.getLeft(), view.getBottom()));
        arrayList.add(new Point(view.getRight(), view.getBottom()));
        float f = 0.0f;
        for (Point point2 : arrayList) {
            float distance = distance(point, point2);
            if (distance > f) {
                f = distance;
            }
        }
        return (int) Math.ceil((double) f);
    }

    public static float distance(Point point, Point point2) {
        return (float) Math.sqrt(Math.pow((double) (point.x - point2.x), 2.0d) + Math.pow((double) (point.y - point2.y), 2.0d));
    }

    public static Animator fadeIn(View view) {
        return fadeIn(view, 250);
    }

    public static Animator fadeIn(View view, int i) {
        return fadeIn(view, i, null);
    }

    public static Animator fadeIn(View view, AnimationListener animationListener) {
        return fadeIn(view, 250, animationListener);
    }

    public static Animator fadeIn(View view, int i, AnimationListener animationListener) {
        if (view.getAlpha() == 1.0f) {
            view.setAlpha(0.0f);
        }
        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(view, "alpha", 1.0f);
        ofFloat.addListener(new DefaultActionAnimationListener(view, animationListener) {
            /* class com.youyi.yyviewsdklibrary.View.searchview.utils.SimpleAnimationUtils.AnonymousClass3 */

            /* access modifiers changed from: package-private */
            @Override // com.youyi.yyviewsdklibrary.View.searchview.utils.SimpleAnimationUtils.DefaultActionAnimationListener
            public void defaultOnAnimationStart(View view) {
                view.setVisibility(View.VISIBLE);
            }
        });
        ofFloat.setDuration((long) i);
        ofFloat.setInterpolator(getDefaultInterpolator());
        return ofFloat;
    }

    public static Animator fadeOut(View view) {
        return fadeOut(view, 250);
    }

    public static Animator fadeOut(View view, int i) {
        return fadeOut(view, i, null);
    }

    public static Animator fadeOut(View view, AnimationListener animationListener) {
        return fadeOut(view, 250, animationListener);
    }

    public static Animator fadeOut(View view, int i, AnimationListener animationListener) {
        ObjectAnimator ofFloat = ObjectAnimator.ofFloat(view, "alpha", 0.0f);
        ofFloat.addListener(new DefaultActionAnimationListener(view, animationListener) {
            /* class com.youyi.yyviewsdklibrary.View.searchview.utils.SimpleAnimationUtils.AnonymousClass4 */

            /* access modifiers changed from: package-private */
            @Override // com.youyi.yyviewsdklibrary.View.searchview.utils.SimpleAnimationUtils.DefaultActionAnimationListener
            public void defaultOnAnimationEnd(View view) {
                view.setVisibility(View.GONE);
            }
        });
        ofFloat.setDuration((long) i);
        ofFloat.setInterpolator(getDefaultInterpolator());
        return ofFloat;
    }

    public static Animator verticalSlideView(View view, int i, int i2) {
        return verticalSlideView(view, i, i2, (AnimationListener) null);
    }

    public static Animator verticalSlideView(View view, int i, int i2, int i3) {
        return verticalSlideView(view, i, i2, i3, null);
    }

    public static Animator verticalSlideView(View view, int i, int i2, AnimationListener animationListener) {
        return verticalSlideView(view, i, i2, 250, animationListener);
    }

    public static Animator verticalSlideView(final View view, int i, int i2, int i3, AnimationListener animationListener) {
        ValueAnimator ofInt = ValueAnimator.ofInt(i, i2);
        ofInt.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            /* class com.youyi.yyviewsdklibrary.View.searchview.utils.SimpleAnimationUtils.AnonymousClass5 */

            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                view.getLayoutParams().height = ((Integer) valueAnimator.getAnimatedValue()).intValue();
                view.requestLayout();
            }
        });
        ofInt.addListener(new DefaultActionAnimationListener(view, animationListener));
        ofInt.setDuration((long) i3);
        ofInt.setInterpolator(getDefaultInterpolator());
        return ofInt;
    }

    protected static Interpolator getDefaultInterpolator() {
        return new FastOutSlowInInterpolator();
    }

    /* access modifiers changed from: private */
    public static class DefaultActionAnimationListener extends AnimatorListenerAdapter {
        private AnimationListener listener;
        private View view;

        /* access modifiers changed from: package-private */
        public void defaultOnAnimationCancel(View view2) {
        }

        /* access modifiers changed from: package-private */
        public void defaultOnAnimationEnd(View view2) {
        }

        /* access modifiers changed from: package-private */
        public void defaultOnAnimationStart(View view2) {
        }

        DefaultActionAnimationListener(View view2, AnimationListener animationListener) {
            this.view = view2;
            this.listener = animationListener;
        }

        public void onAnimationStart(Animator animator) {
            AnimationListener animationListener = this.listener;
            if (animationListener == null || !animationListener.onAnimationStart(this.view)) {
                defaultOnAnimationStart(this.view);
            }
        }

        public void onAnimationEnd(Animator animator) {
            AnimationListener animationListener = this.listener;
            if (animationListener == null || !animationListener.onAnimationEnd(this.view)) {
                defaultOnAnimationEnd(this.view);
            }
        }

        public void onAnimationCancel(Animator animator) {
            AnimationListener animationListener = this.listener;
            if (animationListener == null || !animationListener.onAnimationCancel(this.view)) {
                defaultOnAnimationCancel(this.view);
            }
        }
    }
}
